#include "histogramhsi.h"
#include<QImage>
#include<QColor>
#include<iostream>
#include<string>
#include<QString>
using namespace std;
HistogramHSI::HistogramHSI():Histogram()
{
    histogramHue=new unsigned int[256];
    histogramSaturation=new unsigned int[256];
    histogramIntensity=new unsigned int[256];
    CDFH= new unsigned long[256];
    CDFI= new unsigned long[256];
    CDFS = new unsigned long[256];
}
HistogramHSI::HistogramHSI(QImage* qImage):Histogram(qImage)
{
    histogramHue=new unsigned int[256];
    histogramSaturation=new unsigned int[256];
    histogramIntensity=new unsigned int[256];
    CDFH= new unsigned long[256];
    CDFI= new unsigned long[256];
    CDFS = new unsigned long[256];
}
void HistogramHSI::calcHistogram()
{

    if(ownerImage==NULL)
        return;
    else
    {
        for(int i=0;i<256;i++)
        {
            histogramHue[i]=0;
            histogramSaturation[i]=0;
            histogramIntensity[i]=0;
        }
        QColor retrivedColor;
        for(int x=0;x<ownerImage->width();x++)
            for(int y=0;y<ownerImage->height();y++)
            {
            //    histogramR[qRed(ownerImage->pixel(x,y))]++;
              //  histogramG[qGreen(ownerImage->pixel(x,y))]++;
                //histogramB[qBlue(ownerImage->pixel(x,y))]++;
            QRgb retrivedRgb= this->ownerImage->pixel(x,y);
            retrivedColor= QColor::fromRgb(retrivedRgb);
            histogramHue[retrivedColor.hsvHue()]++;
            histogramIntensity[retrivedColor.value()]++;
            histogramSaturation[retrivedColor.hsvSaturation()]++;

            }

    }
    for(int i=0;i<256;i++)
    {
         cout<<"this is the " << i<<"th Value of the histogram" <<histogramIntensity[i]<<endl;
    }
}
void  HistogramHSI ::calcCDF()
{
    for(int i=0;i<256;i++)
    {
        CDFH[i]=0;
         CDFI[i]=0;
        CDFI[i]=0;
    }
    for(int i=0;i<256;i++)
    {
        for(int j=0;j<=i;j++)
        {
            CDFH[i]=this->histogramHue[j]+CDFH[i];
            CDFS[i]=this->histogramSaturation[j]+CDFS[i];
            CDFI[i]=this->histogramIntensity[j]+CDFI[i];
        }
    }
}

unsigned long * HistogramHSI::getHueCDF()
{
    return this->CDFH;
}
unsigned long * HistogramHSI::getSaturationCDF()
{
    return this->CDFS;
}
unsigned long * HistogramHSI::getIntensityCDF()
{
    return this->CDFI;
}
void HistogramHSI::calcHistImage()
{

}
